package com.czk.duration;

import java.time.Duration;
import java.time.Instant;
import java.util.concurrent.TimeUnit;

/**
 * @Author:ChenZhangKun
 * @Date: 2020/12/29 22:36
 */
public class DurationDemo {
    public static void main(String[] args) throws InterruptedException {
        Instant instant1 = Instant.now();
        TimeUnit.SECONDS.sleep(10);
        Instant instant2 = Instant.now();
        // 计算两者相隔时间
        System.out.println(Duration.between(instant1, instant2));
        System.out.println(Duration.between(instant1,instant2).toMillis());
    }
}
